/*
 * Copyright (c) 2011 Jean-Marc Perronne
 * Ensisa, 12 rue des Freres Lumieres, F-68093 Mulhouse cedex
 * All rights reserved.
 *
 * The copyright of this software is owned by Werner Randelshofer. 
 * You may not use, copy or modify this software, except in  
 * accordance with the license agreement you entered into with  
 * Jean-Marc Perronne. For details see accompanying license terms. 
 */

package fr.uha.ensisa.jmp.connexion_3d;

import java.util.Arrays;

public class Event
{
	public int tx, ty, tz;
	public int rx, ry, rz;
	public boolean buttons[];
	
	public Event(int buttonsNumber)
	{
		this(buttonsNumber, 0, 0, 0, 0, 0, 0);
	}
	
	public Event(int buttonsNumber, int tx, int ty, int tz, int rx, int ry, int rz)
	{
		this.buttons = new boolean[buttonsNumber];
		this.tx = tx;
		this.ty = ty;
		this.tz = tz;
		this.rx = rx; 
		this.ry = ry;
		this.rz = rz;
	}
	
	public Event(Event e)
	{
		this.affect(e);
	}

	public void reset()
	{
		tx=ty=tz=0;
		rx=ry=rz=0;
		Arrays.fill(buttons,false);
	}
	
	public boolean equals(Object o)
	{
		if (o==this) return true;
		if (!(o instanceof Event)) return false;
		
		Event e = (Event) o;
		
		if (e.tx != tx ||
			e.ty != ty ||
			e.tz != tz ||
			e.rx != rx ||
			e.ry != ry ||
			e.rz != rz) return false;
		
		return Arrays.equals(this.buttons, e.buttons);
	}
	
	public Event affect(Event e)
	{
		if (this != e)
		{
			this.tx = e.tx;
			this.ty = e.ty;
			this.tz = e.tz;
			this.rx = e.rx; 
			this.ry = e.ry;
			this.rz = e.rz;
			
			this.buttons = new boolean[e.buttons.length];
			System.arraycopy(e.buttons, 0, this.buttons, 0, e.buttons.length);
		}
		return this;
	}
	
	public String toString()
	{
		StringBuilder tmp = new StringBuilder("event(");
		tmp.append(" T : ").append(tx).append(' ').append(ty).append(' ').append(tz);
		tmp.append(" R : ").append(rx).append(' ').append(ry).append(' ').append(rz);
		tmp.append(" B : ");
		for(boolean b: this.buttons)
			tmp.append((b)?1:0).append(' ');
		
		tmp.append(')');
		return tmp.toString();
	}
}
